#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL fa[maxn],siz[maxn],cnt=0;
LL find(LL x){
    if(fa[x]!=x) return fa[x]=find(fa[x]);
    return fa[x];
}
struct Edge{
    LL u,v,w;
    bool operator <(const Edge& B) const{
        return w<B.w;
    }
}edges[maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n;cin>>n;
   for(LL i=1;i<=n;i++) fa[i]=i,siz[i]=1;
   for(LL i=1;i<n;i++){
       LL u,v,w;cin>>u>>v>>w;
       edges[++cnt].u=u;edges[cnt].v=v;edges[cnt].w=w;
   };
   sort(edges+1,edges+1+cnt);
   LL sum=0;
   for(LL i=1;i<=cnt;i++){
       LL u=find(edges[i].u);LL v=find(edges[i].v);
       if(u==v) continue;
       sum+=edges[i].w*(siz[u])*(siz[v]);
       siz[u]+=siz[v];siz[v]=0;
       fa[v]=u;
   }
   cout<<sum<<"\n";
   return 0;
}
